package JassTranslator;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import framework.JassSyntaxException;
import framework.TranslatorUtils;

public abstract class JassLineTranslator {
	public JassLineTranslator(){
		
	}
	
	public String basicTranslator(String codeString){
		codeString = StringUtils.defaultString(codeString);
		codeString = codeString.replace(" nothing", " void");
		codeString = codeString.replace(" string", " String");
		codeString = codeString.replace(" integer", " int");
		codeString = codeString.replace(" real", " double");
		
		return codeString;
	}
	
	private boolean isAccessSpecified(String codeString){
		codeString = StringUtils.defaultString(codeString).trim();
		if(codeString.startsWith("private")){
			return true;	
		} else if (codeString.startsWith("protected ")) {
			return true;
		} else if (codeString.startsWith("public ")){
			return true;
		}
		return false;
	}
	
	public String checkForAndAddAccessModifier(String codeString){
		if(!isAccessSpecified(codeString)){
			String publicString = "public ";
			int size = codeString.length() + publicString.length();
			codeString = StringUtils.stripStart(codeString, " ");
			codeString = "public " + codeString;
			codeString = StringUtils.leftPad(codeString, size, " ");
		}
		return codeString;
	}

	public abstract boolean isLineOfType(String codeString);
	
	public abstract String mainLineTranslator(String codeString);
	
	public String translateLine(String codeString){
		codeString = basicLineSetup(codeString);
		return mainLineTranslator(codeString);
	}

	
	//If your class doesn't like it override it.
	public String basicLineSetup(String codeString) {
		codeString = StringUtils.defaultString(codeString);
		return basicTranslator(codeString);
	}
	
	public List<String> translateLineList(String codeString){
		return TranslatorUtils.stringToList(translateLine(codeString));
	}
	
	public void checkLineForSyntaxErrors() throws JassSyntaxException{ 
		
	}
}
